<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.7.2.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
<form name="upload" action="upload" enctype="multipart/form-data" method="post">
    <input type="file" name="file" value="file" multiple="multiple"/>
    <button type="submit" name="submit" id="submit" value="上传">上传</button>
</form>
<div>
    <button type="button" id="select" name="select" value="select">查询</button>
</div>
<div id="showdata" name="showdata">数据展示</div>
<form name="1" enctype="text/plain"></form>
<form name="2" enctype="application/x-www-form-urlencoded"></form>
<a id="a" href="./download?nameKey=225596867">下载图片</a>
</body>
<script>
    var res;
    document.getElementById("select").onclick = function () {
        console.log("start");
        axios({
            method: "get",
            url: "http://localhost:8080/FileIo/select"
        }).then(function (resp) {
            let temp = null;
            var str = null;
            res = resp.data;
            console.log(res);
            var table = "<table id='table1'> <tr><td>id</td> <td>文件名</td> <td>文件类型</td><td>文件大小</td><td>上传时间</td> <td>下载 </td></tr> "
            for (var i = 0; i < res.length; i++) {
                temp = res[i];
                console.log(temp);
                table += "<tr > <td id='" + temp.nameKey + "'>" + (i + 1) + "</td>" + "<td>" + temp.name + "</td>" + "<td>" + temp.type + "</td>" + "<td>" + temp.size + "</td>" + "<td>" + new Date(temp.createTime).toLocaleString() +
                    "</td><td><button class='lists' type='button' onclick='download(this)' id='selectbut" + (i + 1) + "\'>" + "下载" +
                    "</button></td></tr>";
            }
            table += "</table>";
            document.getElementById("showdata").innerHTML = table;
        })
    };
    function download(e){
        console.log("下载请求js收到");
        var url = "http://localhost:8080/FileIo/download"
        var Fileid = e.parentNode.parentNode;
        console.log(Fileid.children[0].id);
        window.location.href = "download?nameKey="+Fileid.children[0].id;
    }
/*    function download(e) {
        console.log("下载请求js收到");
        var url = "http://localhost:8080/FileIo/download"
        var Fileid = e.parentNode.parentNode;
        console.log(Fileid.children[0].id);
        $.ajax(url, {
            type: "post",
            data: {"nameKey": Fileid.children[0].id},
            dataType: "json",
            success: function (retMsg) {
                if (retMsg.code == 200) {
                    alert("success");
                } else {
                    alert("false");
                }
            }
        })
    }*/
</script>

</html>